/**
 * 注入js
 * @param jsPath 
 */
function injectCustomJs(jsPath:string) {
    jsPath = jsPath;
    let temp = document.createElement('script');
    temp.setAttribute('type', 'text/javascript');
    // 获得的地址类似：chrome-extension://ihcokhadfjfchaeagdoclpnjdiokfakg/js/inject.js
    temp.src = chrome.runtime.getURL(jsPath);
    temp.onload = function (that) {
        // 放在页面不好看，执行完后移除掉
        that.preventDefault
        temp.parentNode?.removeChild(temp);
    };
    document.body.appendChild(temp);
}

/**
 * 注入css样式
 * @param cssPath 
 */
function injectCustomCss(cssPath:string) {
    var temp = document.createElement('link');
    temp.setAttribute('rel', 'stylesheet');
    // 获得的地址类似：chrome-extension://ihcokhadfjfchaeagdoclpnjdiokfakg/js/inject.js
    temp.href = chrome.runtime.getURL(cssPath);
    document.head.appendChild(temp);
}
export { injectCustomJs, injectCustomCss }